package com.yjd.pub.funds.dao.impl;

import com.yjd.comm.base.dao.impl.BaseDaoImpl;
import com.yjd.comm.funds.dto.FirstPayDto;
import com.yjd.comm.funds.dto.RechAddPriceDto;
import com.yjd.comm.funds.dto.RepaymentPayDto;
import com.yjd.comm.funds.model.FundsModel;
import com.yjd.comm.util.FrameUtil;
import com.yjd.pub.funds.dao.IFundsDao;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <b>description</b>：用户资金表数据访问层 <br>
 * <b>time</b>：2017-09-19 15:07:07 <br>
 * <b>author</b>： carl
 */
@Component("fundsDao")
public class FundsDaoImpl extends BaseDaoImpl implements IFundsDao {

	private static final String SQLMAPNAMESPACE = FundsModel.class.getName();
	private static final String PKNAME = "user_id";

	@Override
	public String getPrimaryKeyName() {
		return PKNAME;
	}

	@Override
	public String getSqlmapNamespace() {
		return SQLMAPNAMESPACE;
	}

	/**
	 * 充值资金增加
	 *
	 * @param dto
	 * @return
	 * @throws Exception
	 */
	@Override
	public int rechAddPrice(RechAddPriceDto dto) throws Exception {
		if(dto==null){
			FrameUtil.throwBaseException1("请求的参数不能为空！！");
		}
		return this.getSqlMap(true).update(this.getStatement("rechAddPrice"),dto);
	}

	/**
	 * 首付扣款
	 * @param dto
	 * @return
	 * @throws Exception
	 */
	@Override
	public int firstPayReducePrice(FirstPayDto dto) throws Exception {
		if(dto==null){
			FrameUtil.throwBaseException1("请求的参数不能为空！！");
		}
		return this.getSqlMap(true).update(this.getStatement("firstPayReducePrice"),dto);
	}

	/**
	 * 还款 扣款
	 *
	 * @param dto
	 * @return
	 * @throws Exception
	 */
	@Override
	public int repaymentPayReducePrice(RepaymentPayDto dto) throws Exception {
		if(dto==null){
			FrameUtil.throwBaseException1("请求的参数不能为空！！");
		}
		return this.getSqlMap(true).update(this.getStatement("repaymentPayReducePrice"),dto);
	}

	@Override
	public int increasePrice(Map paramMap) throws Exception {
		return this.getSqlMap(true).update(this.getStatement("increasePrice"), paramMap);
	}

	@Override
	public List queryUserFunds(Map<String, Object> paramMap, boolean write) throws Exception {
		return this.getSqlMap(write).queryForList(this.getStatement("queryUserFunds"), paramMap);
	}

	/**
	 * 商户确认退单更新资金情况
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public int addPriceOfOrderRturn(Map<String, Object> paramMap) throws Exception {
		return this.getSqlMap(true).update(this.getStatement("addPriceOfOrderRturn"), paramMap);
	}
}
